import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },

  {
    path: "/documentation",
    component: Layout,
    children: [
      {
        path: "documentation",
        name: "Documentation",
        component: () => import('@/views/documentation/index'),
        meta: { title: "文档", icon: "documentation" },
      },
    ],
  },

  {
    path: "/form",
    component: Layout,
    children: [
      {
        path: "index",
        name: "Form",
        component: () => import("@/views/form/index"),
        meta: { title: "引导页", icon: "guide" },
      },
    ],
  },

  {
    path: "/permissions",
    component: Layout,
    meta: {
      title: "权限测试页",
      icon: "lock",
    },
    children: [
      {
        path: "permissions",
        component: () => import("@/views/permissions/PermissionsPage/index"), // Parent router-view
        name: "Menu1",
        meta: { title: "页面权限" },
      },
      {
        path: "instruction",
        component: () => import("@/views/permissions/instruction/index"),
        name: "Instruction",
        meta: { title: "指令权限" },
      },
      {
        path: "RoleAuthorization",
        component: () => import("@/views/permissions/RoleAuthorization/index"),
        name: "RoleAuthorization",
        meta: { title: "角色权限" },
      },
    ],
  },
  {
    path: "/icon",
    component: Layout,
    children: [
      {
        path: "icon",
        name: 'Icon',
        component: () => import('@/views/icon/index.vue'),
        meta: { title: "图标", icon: "icon" },
      },
    ],
  },
  {
    path: "/component",
    component: Layout,
    meta: {
      title: "组件",
      icon: "nested",
    },
    children: [
      {
        path: "RichTextEditor",
        component: () => import("@/views/component/RichTextEditor"), // Parent router-view
        name: "RichTextEditor",
        meta: { title: "富文本编辑器" },
      },
      {
        path: "markdown",
        component: () => import("@/views/component/markdown"),
        name: "markdown",
        meta: { title: "Markdown" },
      },
      {
        path: "JSON",
        component: () => import("@/views/component/JSON"),
        name: "JSON",
        meta: { title: "JSON编辑器" },
      },
      {
        path: "splitpane",
        component: () => import("@/views/component/splitpane"),
        name: "Splitpane",
        meta: { title: "Splitpane" },
      },
      {
        path: "upload",
        component: () => import("@/views/component/upload"),
        name: "upload",
        meta: { title: "头像上传" },
      },
      {
        path: "dropzone",
        component: () => import("@/views/component/dropzone"),
        name: "Dropzone",
        meta: { title: "Dropzone" },
      },
      {
        path: "select",
        component: () => import("@/views/component/select"),
        name: "Select",
        meta: { title: "Select" },
      },
      {
        path: "conutTo",
        component: () => import("@/views/component/conutTo"),
        name: "ConutTo",
        meta: { title: "Conut To" },
      },
      {
        path: "minComponent",
        component: () => import("@/views/component/minComponent"),
        name: "MinComponent",
        meta: { title: "小组件" },
      },
      {
        path: "backTop",
        component: () => import("@/views/component/backTop"),
        name: "BackTop",
        meta: { title: "返回顶部" },
      },
      {
        path: "dialog",
        component: () => import("@/views/component/dialog"),
        name: "Dialog",
        meta: { title: "拖拽 Dialog" },
      },
      /*  {
         path: "select",
         component: () => import("@/views/component/select"),
         name: "Select",
         meta: { title: "拖拽 Select" },
       }, */
      {
        path: "listDrag",
        component: () => import("@/views/component/listDrag"),
        name: "ListDrag",
        meta: { title: "列表拖拽" },
      },
      {
        path: "kanbanDrag",
        component: () => import("@/views/component/kanbanDrag"),
        name: "KanbanDrag",
        meta: { title: "可拖拽看板" },
      },
    ],
  },

  {
    path: "/keyboardChart",
    component: Layout,
    meta: {
      title: "图表",
      icon: "nested",
    },
    children: [
      {
        path: "keyboardChart",
        component: () => import("@/views/chart/keyboardChart"), // Parent router-view
        name: "KeyboardChart",
        meta: { title: "键盘图表" },
      },
      {
        path: "lineChart",
        component: () => import("@/views/chart/lineChart"),
        name: "LineChart",
        meta: { title: "折线图" },
      },
      {
        path: "hybridChart",
        component: () => import("@/views/chart/hybridChart"),
        name: "HybridChart",
        meta: { title: "混合图表" },
      },
    ],
  },
  {
    path: "/MenuOne",
    component: Layout,
    meta: {
      title: "路由嵌套",
      icon: "nested",
    },
    children: [
      {
        path: "menuOne",
        component: () => import("@/views/nested/menuOne"), // Parent router-view
        name: "MenuOne",
        meta: { title: "菜单1" },
        children: [
          {
            path: "one",
            component: () => import("@/views/nested/menuOne/children/one"),
            name: "One",
            meta: { title: "菜单1-1" },
          },
          {
            path: "two",
            component: () => import("@/views/nested/menuOne/children/two"),
            name: "Two",
            meta: { title: "菜单1-2" },
            children: [
              {
                path: "LevelOne",
                component: () => import("@/views/nested/menuOne/children/two/Level/LevelOne"),
                name: "LevelOne",
                meta: { title: "菜单1-2-1" },
              },
              {
                path: "LevelTwo",
                component: () => import("@/views/nested/menuOne/children/two/Level/LevelTwo"),
                name: "LevelTwo",
                meta: { title: "菜单1-2-2" },
              },
              {
                path: "LevelThree",
                component: () => import("@/views/nested/menuOne/children/two/Level/LevelThree"),
                name: "LevelThree",
                meta: { title: "菜单1-2-3" },
              },
            ]
          },
          {
            path: "three",
            component: () => import("@/views/nested/menuOne/children/three"),
            name: "Three",
            meta: { title: "菜单1-3" },
          },
        ]
      },
      {
        path: "menuTwo",
        component: () => import("@/views/nested/menuTwo"),
        name: "MenuTwo",
        meta: { title: "菜单2" },
      },
    ],
  },
  {
    path: "/dynamicTable",
    component: Layout,
    meta: {
      title: "Table",
      icon: "nested",
    },
    children: [
      {
        path: "dynamicTable",
        name: 'DynamicTable',
        component: () => import('@/views/table/dynamicTable'),
        meta: { title: "动态 Table" },
      },
      {
        path: "dragTable",
        name: 'DragTable',
        component: () => import('@/views/table/dragTable'),
        meta: { title: "拖拽 Table" },
      },
      {
        path: "editorTable",
        name: 'EditorTable',
        component: () => import('@/views/table/editorTable'),
        meta: { title: "Table 内编辑" },
      },
      {
        path: "comprehensive",
        name: 'Comprehensive',
        component: () => import('@/views/table/comprehensive'),
        meta: { title: "综合 Table" },
      },
    ],
  },
  {
    path: "/createArticle",
    component: Layout,
    meta: {
      title: "综合实例",
      icon: "nested",
    },
    children: [
      {
        path: 'createArticle',
        name: 'CreateArticle',
        component: () => import('@/views/comprehensive/createArticle'),
        meta: {
          title: "创建文章",
          icon: "el-icon-edit-outline",
        },
      },
      {
        path: 'listArticle',
        name: 'ListArticle',
        component: () => import('@/views/comprehensive/listArticle'),
        meta: {
          title: "文章列表",
          icon: "nested",
        },
      }
    ]
  },
  {
    path: "/Page401",
    component: Layout,
    meta: {
      title: "错误页面",
      icon: "404",
    },
    children: [
      {
        path: "Page401",
        component: () => import('@/views/errorPage/Page401.vue'),
        name: 'Page401',
        meta: { title: "401" },
      },
      {
        path: "Page404",
        component: () => import('@/views/errorPage/Page404.vue'),
        name: 'Page404',
        meta: { title: "404" },
      },
    ],
  },

  /*   {
      path: "/errorPage",
      component: Layout,
      children: [
        {
          path: "errorPage",
          name: "ErrorPage",
          component: () => import('@/views/errorLog/index.vue'),
          meta: { title: "错误页面", icon: "el-icon-s-help" },
        },
      ],
    },
   */
  {
    path: "/errorLog",
    component: Layout,
    children: [
      {
        path: "errorLog",
        name: "ErrorLog",
        component: () => import('@/views/errorLog/index'),
        meta: { title: "错误日志", icon: "bug" },
      },
    ],
  },

  {
    path: "external-link",
    component: Layout,
    children: [
      {
        path: "https://panjiachen.github.io/vue-element-admin-site/#/",
        meta: { title: "外部链接", icon: "link" },
      },
    ],
  },
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
